<script>
	import initApp from '@/common/appInit.js';
	
	export default {
		globalData: {
			appVersion: {},
			config:{},
			imService : null
		},
		onLaunch: function() {
			this.initSite()
			initApp();
			// 将状态栏高度添加到nav标题和navsearch里
			this.$store.state.global.navHeight = String(Number(this.$store.state.global.navHeight) + this.$store.state.global.statusHeight)
			if(!this.$store.state.global.os.mp){ // 小程序时显示nav与navSearch 所以小程序时不再次添加状态栏高度
				this.$store.state.global.navSearchHeight = String(Number(this.$store.state.global.navSearchHeight) + this.$store.state.global.statusHeight)
			}
		},
		onShow: function() {
			
		},
		onHide: function() {
			
		},
		methods : {
			initSite: async function() {
				await this.$store.dispatch('global/getServerTime')
				// if(this.$store.state.site.globalSiteCode == '' && !this.$store.state.site.expiration_time){
				// 	// await this.$store.dispatch('site/getCurrentSite').then(res => {
				// 	// 	this.$store.dispatch('site/setGlobalSite', res)
				// 	// })
				// 	let res = await this.$store.dispatch('site/getCurrentSite')
				// 	console.log(res)
				// 	await this.$store.dispatch('site/setGlobalSite', res)
				// }
				await this.$store.dispatch('site/getHomePage')
				await this.$store.dispatch('GoEasy/initGoEasy')
				await this.$store.dispatch('GoEasy/connectGoEasy')
				
				//监听会话
				let self = this;
				if(this.$store.state.GoEasy.goEasy){
					this.$store.state.GoEasy.goEasy.im.on(this.$store.state.GoEasy.GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, (content) => {
						this.setUnreadAmount(content.unreadTotal);
					});
				}
			},
			setUnreadAmount (unreadTotal) {
				this.unreadTotal = unreadTotal;
				if(this.unreadTotal > 0) {
					uni.setTabBarBadge({
						index: 3,
						text: this.unreadTotal.toString()
					});
				}else{
					uni.removeTabBarBadge({
						index: 3
					});
				}
			}
		}
	}
</script>

<style>
	// #ifndef APP-PLUS-NVUE
	/*每个页面公共css */
	@import './static/style/uni.css';
	// #endif
</style>
